var member_id  = ws = '';
document.addEventListener('plusready',function(){
	ws = plus.webview.currentWebview();
	member_id = plus.storage.getItem('id');
	console.log(apiRoot + "?act=member_order&op=order_list"+member_id);
	plus.nativeUI.showWaiting('加载中...');
	$.ajax({ 
		type:"post",
		url:apiRoot + "?act=member_order&op=order_list",
		data:{member_id:member_id,ordertype:3,driving:1},
		dataType:'json', 
		success:function(info){
			console.log(JSON.stringify(info));
			if(info.code == 200){
				var html1 = '';
				var html2 = '';
				var html3 = '';
				var html4 = ''; 
				var statea = stateb = statec = stated = 0;
				$.each(info.datas.order_group_list, function(k1,v1) {
					$.each(v1.order_list, function(k2,v2) {
						$.each(v2.extend_order_goods, function(k,v) {
							switch(v2.order_state){
								case '10' :
								statea++;
									html1 += '<ul class="mui-table-view">' +
												 '<li class="mui-table-view-cell mui-media Driving" data-order_id="'+ v2.order_id +'">'+
													 '<img class="mui-media-object mui-pull-left" src="'+ v.goods_image_url +'">'+
											 		 '<div class="mui-media-body">'+
												 		'<b>'+ v.goods_name +'</b>'+
												 		'<p>'+ v.goods_custom[1].value +'</p>'+										
												 		'<p class="mui-h6">'+v.goods_custom[2].value+'</p>'+
													'</div>'+
												 '</li>'+
											  '</ul>';
								break;
								case '20' :
									stateb++;
									html2 += '<ul class="mui-table-view">' +
												 '<li class="mui-table-view-cell mui-media Driving" data-order_id="'+ v2.order_id +'">'+
													 '<img class="mui-media-object mui-pull-left" src="'+ v.goods_image_url +'">'+
											 		 '<div class="mui-media-body">'+
												 		'<b>'+ v.goods_name +'</b>'+
												 		'<p>'+ v.goods_custom[1].value +'</p>'+										
												 		'<p class="mui-h6">'+v.goods_custom[2].value+'</p>'+
													'</div>'+
												 '</li>'+
											  '</ul>';
								break;
								case '40' :
									statec++;
									html3 += '<ul class="mui-table-view">' +
												 '<li class="mui-table-view-cell mui-media Driving" data-order_id="'+ v2.order_id +'">'+
													 '<img class="mui-media-object mui-pull-left" src="'+ v.goods_image_url +'">'+
											 		 '<div class="mui-media-body">'+
												 		'<b>'+ v.goods_name +'</b>'+
												 		'<p>'+ v.goods_custom[1].value +'</p>'+										
												 		'<p class="mui-h6">'+v.goods_custom[2].value+'</p>'+
													'</div>'+
												 '</li>'+
											  '</ul>';
								break;   
								case '0' :
									stated++;
									html4 += '<ul class="mui-table-view">' +
												 '<li class="mui-table-view-cell mui-media Driving" data-order_id="'+ v2.order_id +'">'+
													 '<img class="mui-media-object mui-pull-left" src="'+ v.goods_image_url +'">'+
											 		 '<div class="mui-media-body">'+
												 		'<b>'+ v.goods_name +'</b>'+
												 		'<p>'+ v.goods_custom[1].value +'</p>'+										
												 		'<p class="mui-h6">'+v.goods_custom[2].value+'</p>'+
													'</div>'+
												 '</li>'+
											  '</ul>';
											  
								break;
							}
						});
					});
				}); 
				var state = '<div style="margin: 40px auto;text-align: center;font-size: 1.2em;">还没有数据...</div>'; 
				if(statea > 0){
					$('#item1mobile .mui-scroll').html(html1);
				}else{
					$('#item1mobile .mui-scroll').html(state);
				}
				if(stateb > 0){
					$('#item2mobile .mui-scroll').html(html2);
				}else{
					$('#item2mobile .mui-scroll').html(state);
				}
				if(statec > 0){
					$('#item3mobile .mui-scroll').html(html3);
				}else{
					$('#item3mobile .mui-scroll').html(state);
				}
				if(stated > 0){
					$('#item4mobile .mui-scroll').html(html4);
				}else{
					$('#item4mobile .mui-scroll').html(state);
				}
				
				
				
				
			}
			plus.nativeUI.closeWaiting();
			//删除订单
			$('.travel_upl').on('click',function(){
				var _this = $(this);
				var order_id = _this.attr('data-order_id');
				order_receive(member_id,order_id);
			})
			//订单详情
			$('.Driving').unbind('tap');
			$('.Driving').on('tap',function(){
				var _this = $(this);
				var order_id = _this.attr('data-order_id');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./Driving_off.html','Driving_off.html',{},{order_id:order_id,spage:ws.id});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
			
			
		},
		error:function(e){
			plus.nativeUI.closeWaiting();
			console.log(JSON.stringify(e));
			error();
		}
	});
	
},false)